package com.study.talk.adapter;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.study.talk.R;
import com.study.talk.app.base.BaseActivity;
import com.study.talk.databinding.MomentLikeItemViewBinding;
import com.study.talk.entity.MomentLike;

import java.util.ArrayList;

/**
 * @author thor
 * @description:
 * @date 2024/9/30 15:45
 */
public class MomentLikeListAdapter extends RecyclerView.Adapter<MomentLikeListAdapter.ViewHolder> {

    ArrayList<MomentLike> data;

    BaseActivity activity;

    public final int HEADER_VIEW = 999;

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == HEADER_VIEW) {
            return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.heart, parent, false));
        } else {
            return new ViewHolder(MomentLikeItemViewBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
        }
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (getItemViewType(position) == HEADER_VIEW) return;
        if (position == data.size() - 1) {
            holder.viewBinding.momentListViewItemLikeText.setText(data.get(position).getUserName());
        } else {
            holder.viewBinding.momentListViewItemLikeText.setText(data.get(position).getUserName() + ",");
        }
    }

    @Override
    public int getItemViewType(int position) {
        return position == data.size() ? HEADER_VIEW : 0;
    }

    @Override
    public int getItemCount() {
        return data.size() + 1;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        public MomentLikeItemViewBinding viewBinding;

        public ViewHolder(@NonNull MomentLikeItemViewBinding viewBinding) {
            super(viewBinding.getRoot());
            this.viewBinding = viewBinding;
        }

        public ViewHolder(View view) {
            super(view);
        }
    }
}
